<template>
<div>
<van-nav-bar
  title="账号登录"
  left-arrow
  @click-left="onClickLeft"
/>
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请输入账号' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请输入账号' }]"
  />
  <div style="margin: 16px;">
    <van-button block type="primary" native-type="submit">登录</van-button>
  </div>
</van-form>
<router-link to='/login'>没有账号，去注册~</router-link>
</div>
</template>

<script>
import {register} from '../api/user'
import {setToken} from '../until/stroage'
export default {
    name:'RG',
 data () {
 return {
    username: '',
    password: '',
   }
 },

components: {},

 methods: {
    async onSubmit(values) {
      console.log('submit', values);
      const res= await register(values)
      console.log(res);
      if(res.data.status===200){
        this.$toast.success('登录成功')
        setToken(res.data.body.token)
        this.$router.push('/Mymessage')
      }
    },
     onClickLeft() {
        this.$router.back()
    },
 }
}
</script>

<style scoped>
a{
    text-align: center;
    display: block;
    color: #666666;
}
</style>